package com.huibur.devicecheck.request;

import com.huibur.devicecheck.session.UserSubject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SessionContext {

    private static final ThreadLocal<UserSubject> USER_SUBJECT_THREAD_LOCAL = new ThreadLocal<>();

    public static UserSubject getCurrentUserSubject() {
        return USER_SUBJECT_THREAD_LOCAL.get();
    }

    public static void setUserSubject(UserSubject userSubject) {
        SessionContext.USER_SUBJECT_THREAD_LOCAL.set(userSubject);
    }

    public static void clearSession() {
        USER_SUBJECT_THREAD_LOCAL.remove();
    }

}